using System;
using System.Collections;
using System.Reflection;
using DataBroker.Dao;

namespace FirebirdDAO
{
    [Serializable]
    public class Department_parent : DepartmentTable
    {
        public override string TableName ()
        {
            return "DepartmentTable";
        }
    }
    public class Department_child : DepartmentTable
    {
        public override string TableName()
        {
            return "DepartmentTable";
        }
    }
    ///<summary>
    /// DAO Class for the DepartmentTable table.
    ///</summary>
    public class DepartmentTable : Entity
    {
        private String _DEPT_NO;
        private String _DEPARTMENT;
        private String _HEAD_DEPT;
        private Int16 _MNGR_NO;
        private Decimal _BUDGET;
        private String _LOCATION;
        private String _PHONE_NO;

        ///Default constructor
        public DepartmentTable()
        {

        }

        /// <summary>
        /// Constructor for joins. 
        /// Available CHILD tables to join with:
        ///    - DepartmentTable ( Department_integ_17 )
        ///    - Employee ( Employee_integ_28 )
        ///    - Proj_dept_budget ( Proj_dept_budget_integ_47 )
        /// Available PARENT tables to join with:
        ///    - DepartmentTable
        ///    - Employee
        /// </summary>
        public DepartmentTable(bool Flat, params Entity[] entities)
            : this()
        {
            foreach (Entity entity in entities)
            {
                string[] entityParts = entity.GetType().ToString().Split('.');
                string entityName = entityParts[entityParts.Length - 1];
                PropertyInfo pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, new EntityCollection(entity), null);
                }
                entityName = entityName + "_";
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
            }
            SetFlat(Flat);
        }

        ///Constructor for Joins with flat hierarchy
        public DepartmentTable(params Entity[] entities)
            : this(true, entities)
        {
        }

        ///<summary>
        /// Property for column Dept_no.
        ///</summary>
        [IsNotNullable]
        [IsPK]
        [MaxLength(3)]
        public String Dept_no
        {
            get
            {
                return _DEPT_NO;
            }
            set
            {
                _DEPT_NO = value;
            }
        }
        ///<summary>
        /// Property for column DepartmentTable.
        ///</summary>
        [IsNotNullable]
        [MaxLength(25)]
        public String Department
        {
            get
            {
                return _DEPARTMENT;
            }
            set
            {
                _DEPARTMENT = value;
            }
        }
        ///<summary>
        /// Property for column Head_dept.
        ///</summary>
        [MaxLength(3)]
        public String Head_dept
        {
            get
            {
                return _HEAD_DEPT;
            }
            set
            {
                _HEAD_DEPT = value;
            }
        }
        ///<summary>
        /// Property for column Mngr_no.
        ///</summary>
        public Int16 Mngr_no
        {
            get
            {
                return _MNGR_NO;
            }
            set
            {
                _MNGR_NO = value;
            }
        }
        ///<summary>
        /// Property for column Budget.
        ///</summary>
        public Decimal Budget
        {
            get
            {
                return _BUDGET;
            }
            set
            {
                _BUDGET = value;
            }
        }
        ///<summary>
        /// Property for column Location.
        ///</summary>
        [MaxLength(15)]
        public String Location
        {
            get
            {
                return _LOCATION;
            }
            set
            {
                _LOCATION = value;
            }
        }
        ///<summary>
        /// Property for column Phone_no.
        ///</summary>
        [MaxLength(20)]
        public String Phone_no
        {
            get
            {
                return _PHONE_NO;
            }
            set
            {
                _PHONE_NO = value;
            }
        }

        #region Department_child
        private EntityCollection _Department_child;
        ///<summary>
        /// Related table Department_child as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(Department_child), "Department_child")]
        public EntityCollection Department_child
        {
            get
            {
                return _Department_child;
            }

            set
            {
                _Department_child = value;
            }
        }
        private Department_child _Department_child_;
        ///<summary>
        /// Related table Department_child as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public Department_child Department_child_
        {
            get
            {
                return _Department_child_;
            }

            set
            {
                _Department_child_ = value;
            }
        }
        #endregion

        #region Manager
        private EntityCollection _Manager;
        ///<summary>
        /// Related table Manager as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(Manager), "Manager")]
        public EntityCollection Manager
        {
            get
            {
                return _Manager;
            }

            set
            {
                _Manager = value;
            }
        }
        private Manager _Manager_;
        ///<summary>
        /// Related table Manager as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public Manager Manager_
        {
            get
            {
                return _Manager_;
            }

            set
            {
                _Manager_ = value;
            }
        }
        #endregion

        #region Proj_dept_budget
        private EntityCollection _Proj_dept_budget;
        ///<summary>
        /// Related table Proj_dept_budget as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(Proj_dept_budget), "Proj_dept_budget")]
        public EntityCollection Proj_dept_budget
        {
            get
            {
                return _Proj_dept_budget;
            }

            set
            {
                _Proj_dept_budget = value;
            }
        }
        private Proj_dept_budget _Proj_dept_budget_;
        ///<summary>
        /// Related table Proj_dept_budget as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public Proj_dept_budget Proj_dept_budget_
        {
            get
            {
                return _Proj_dept_budget_;
            }

            set
            {
                _Proj_dept_budget_ = value;
            }
        }
        #endregion
        #region DepartmentTable
        private EntityCollection _Department_parent;
        ///<summary>
        /// Related table Department_parent as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(Department_parent), "Department_parent")]
        public EntityCollection Department_parent
        {
            get
            {
                return _Department_parent;
            }

            set
            {
                _Department_parent = value;
            }
        }
        private Department_parent _Department_parent_;
        ///<summary>
        /// Related table Department_parent as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public Department_parent Department_parent_
        {
            get
            {
                return _Department_parent_;
            }

            set
            {
                _Department_parent_ = value;
            }
        }
        #endregion
        #region Employee
        private EntityCollection _Employee;
        ///<summary>
        /// Related table Employee as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(Employee), "Employee")]
        public EntityCollection Employee
        {
            get
            {
                return _Employee;
            }

            set
            {
                _Employee = value;
            }
        }
        private Employee _Employee_;
        ///<summary>
        /// Related table Employee as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public Employee Employee_
        {
            get
            {
                return _Employee_;
            }

            set
            {
                _Employee_ = value;
            }
        }
        #endregion
        /// <summary>
        /// Gets join for current entity and table.
        /// </summary>
        /// <param name="tableName">Table to join with entity.</param>
        /// <returns>Join definition for entity and table.</returns>
        public override DBJoin GetJoin(string tableName)
        {
            if (string.Compare(tableName, "Department_child", StringComparison.OrdinalIgnoreCase) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Head_dept");
                right.Add(GetType().Name + ".Dept_no");
                return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
            }
            if (string.Compare(tableName, "Employee", StringComparison.OrdinalIgnoreCase) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Dept_no");
                right.Add(GetType().Name + ".Dept_no");
                return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
            }
            if (string.Compare(tableName, "Proj_dept_budget", StringComparison.OrdinalIgnoreCase) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Dept_no");
                right.Add(GetType().Name + ".Dept_no");
                return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
            }
            if (string.Compare(tableName, "Department", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Dept_no");
                right.Add(GetType().Name + ".Head_dept");
                return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
            }
            if (string.Compare(tableName, "Employee", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Emp_no");
                right.Add(GetType().Name + ".Mngr_no");
                return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
            }
            return null;
        }
    }
}


